package com.anolesoft.yr.mbus.part.mapper;

import com.anolesoft.yr.mbus.part.entity.PartModelTreeQueryDO;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.mapping.FetchType;
import org.apache.ibatis.type.JdbcType;
import org.apache.ibatis.type.LocalDateTimeTypeHandler;

import java.util.List;

/**
 * @author zhj
 * @date 2020/9/11 13:52
 */
@Mapper
public interface PartModelTreeQueryMapper {
    @Results(id = "PartModelResultMap", value = {
            @Result(id = true, column = "objuid", property = "objuid", jdbcType = JdbcType.VARCHAR),
            @Result(column = "parent_part_model_uid", property = "parentPartModelUid", jdbcType = JdbcType.VARCHAR),
            @Result(column = "part_type_uid", property = "partTypeUid", jdbcType = JdbcType.VARCHAR),
            @Result(column = "part_code", property = "partCode", jdbcType = JdbcType.VARCHAR),
            @Result(column = "part_brand", property = "partBrand", jdbcType = JdbcType.VARCHAR),
            @Result(column = "part_model", property = "partModel", jdbcType = JdbcType.VARCHAR),
            @Result(column = "vice_model", property = "viceModel", jdbcType = JdbcType.VARCHAR),
            @Result(column = "part_name", property = "partName", jdbcType = JdbcType.VARCHAR),
            @Result(column = "part_specification", property = "partSpecification", jdbcType = JdbcType.VARCHAR),
            @Result(column = "unit", property = "unit", jdbcType = JdbcType.VARCHAR),
            @Result(column = "quantity", property = "quantity", jdbcType = JdbcType.INTEGER),
            @Result(column = "part_type_uid", property = "partType", one = @One(select = "com.anolesoft.yr.mbus.part.mapper.PartTypeMapper.selectOneById", fetchType = FetchType.EAGER)),
            @Result(column = "objuid", property = "children", many = @Many(select = "com.anolesoft.yr.mbus.part.mapper.PartModelTreeQueryMapper.selectTree", fetchType = FetchType.LAZY)),
    })
    @Select("select " +
            "objuid, parent_part_model_uid, part_type_uid, part_code, part_brand, " +
            "part_model, vice_model, part_name, part_specification, unit, quantity " +
            "from part_model where del_flag = 0 and parent_part_model_uid = #{parentId,jdbcType=VARCHAR} ")
    List<PartModelTreeQueryDO> selectTree(@Param("parentId") String parentId);
}
